package com.huatai.manage.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.huatai.common.api.R;
import com.huatai.manage.entity.TbCodeManageEntity;
import com.huatai.manage.query.PageQuery;
import com.huatai.manage.query.RemoveQuery;
import com.huatai.manage.service.TbCodeManageService;
import com.huatai.manage.utils.ComUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 编码管理（字典）; 前端控制器
 * </p>
 *
 * @author luoxc
 * @since 2023-07-05
 */
@RestController
@RequestMapping("codeManage")
@Api(value = "编码管理", tags = "编码管理")
public class TbCodeManageController {

	@Autowired
	private TbCodeManageService service;

	@ApiOperationSupport(order = 1, includeParameters = {
		"pageQuery.current",
		"pageQuery.size",
		"pageQuery.data.codeName",
		"pageQuery.data.codeMain"
	})
	@PostMapping("pageList")
	@ApiOperation(value = "分页查询", notes = "分页查询")
	public R pageList(@RequestBody PageQuery<TbCodeManageEntity> pageQuery) {
		return R.data(this.service.pageList(pageQuery));
	}

	@GetMapping("list")
	@ApiOperation(value = "查询所有数据", notes = "查询所有数据")
	public R list() {
		return R.data(this.service.selectAll());
	}

	@GetMapping("listByCodeMain")
	@ApiOperation(value = "主编码类型查询", notes = "主编码类型查询")
	public R listByMainId(@ApiParam(name = "codeMain",value = "主编码", required = true) @RequestParam("codeMain") String codeMain) {
		return R.data(this.service.listByCodeMain(codeMain));
	}

	@PostMapping("getByCodeMainId")
	@ApiOperation(value = "通过编码id查询单条数据", notes = "通过编码id查询单条数据")
	public R getOne(@ApiParam(name = "codeId",value = "编码id", required = true) @RequestParam("codeId") String codeId) {
		return R.data(this.service.getByCodeId(codeId));
	}

	@PostMapping("insert")
	@ApiOperation(value = "新增数据", notes = "新增数据")
	public R insert(@Valid @RequestBody TbCodeManageEntity tbCodeManageEntity) {
		return R.status(this.service.save(tbCodeManageEntity.setCodeId(ComUtil.getUUID())));
	}

	@PostMapping("update")
	@ApiOperation(value = "修改数据", notes = "修改数据")
	public R update(@Valid @RequestBody TbCodeManageEntity tbCodeManageEntity) {
		return R.status(this.service.update(tbCodeManageEntity));
	}

	@PostMapping("removes")
	@ApiOperation(value = "批量删除", notes = "批量删除")
	public R removes(@RequestBody RemoveQuery remove) {
		return R.status(this.service.removes(remove.getIds()));
	}


}
